<template>
	<view class="bait">
		<!-- 顶部导航 -->
		<!-- #ifdef MP || APP-PLUS -->
		<view class="bgColor" :style="{ height: statusBarHeight}"></view>
		<!-- #endif -->
		<view class="header">
			<view class="head-menu" >
				<view class="iconfont icon-ic_leftarrow" @click="goback"></view>
				<view class="iconfont icon-ic_home" @click="goHome" ></view>
			</view>
			<view class="title">渔讯</view>
		</view>
		<view class='newsList'>
			<view class='nav bg-f' v-if="navList.length > 0">
				<scroll-view class="scroll-view_x" scroll-x scroll-with-animation :scroll-left="scrollLeft"
					style="width:auto;overflow:hidden;">
					<block v-for="(item,index) in navList" :key="index">
						<view class='item' :class='active==item.article_category_id?"on":""'
							@click='tabSelect(item.article_category_id)'>
							<view>{{item.title}}</view>
							<view class='line bg-color' v-if="active==item.article_category_id"></view>
						</view>
					</block>
				</scroll-view>
			</view>
			<view class='list pad20'>
				<block v-for="(item,index) in articleList" :key="index">
					<navigator :url='"/pages/news/news_details/index?id="+item.article_id' hover-class='none'
						class='item acea-row row-between-wrapper bg-f boder-24 mt20'>
						<view class='text acea-row row-column-between'>
							<view class='name line2'>{{item.title}}</view>
							<view>{{item.create_time}}</view>
						</view>
						<view class='pictrue'>
							<image :src='item.image_input'></image>
						</view>
					</navigator>
				</block>
			</view>
		</view>
		<block v-if="articleList.length == 0 && (page != 1 || active== 0)">
			<emptyPage title="暂无新闻信息～" :noImage="`${domain}/static/images/empty-box.png`"></emptyPage>
		</block>
		<home></home>

		<!-- 底部导航菜单 -->
		<storeTabbar :value="4" :storeId = "storeID"></storeTabbar>
	</view>
</template>

<script>
	import storeTabbar from '@/components/storeTabbar/storeTabbar.vue';
	import {
		getArticleCategoryList,
		getArticleList,
		getArticleHotList
	} from '@/api/api.js';
	import home from '@/components/home';
	import {
		HTTP_REQUEST_URL
	} from '@/config/app';
	import emptyPage from '@/components/emptyPage.vue';

	export default {
		components: {
			storeTabbar,
			home,
			emptyPage
		},
		data() {
			return {
				storeID:null, // 商铺id
				statusBarHeight: 0,
				height: 0,
				homeTop: 59,
				currentPage: false,
				domain: HTTP_REQUEST_URL,
				imgUrls: [],
				articleList: [],
				indicatorDots: false,
				circular: true,
				autoplay: true,
				interval: 3000,
				duration: 500,
				navList: [],
				active: 0,
				page: 1,
				limit: 8,
				status: false,
				scrollLeft: 0
			};
		},
		onLoad(options) {
			this.storeID = Number(options.storeID);
			if (!options.storeID) return this.$util.Tips({
				title: '缺少参数无法查看钓场鱼汛'
			}, {
				tab: 1,
				url: '/pages/fishingPond/index'
			});
			this.statusBarHeight = uni.getSystemInfoSync().statusBarHeight + 'px';
			this.height = uni.getSystemInfoSync().windowHeight - this.tabBarHeight - this.navHeight;
			this.getArticleCate();
			this.status = false;
			this.page = 1;
			this.articleList = [];
			
		},
		onReachBottom: function() {
			this.getCidArticle();
		},
		onReady() {

		},
		methods: {

			goback: function() {
				// uni.navigateBack();
				uni.switchTab({
					url:'/pages/fishingPond/index'
				})
			},
			// 首页
			goHome() {
				uni.switchTab({
					url: '/pages/index/index'
				});
			},
			
			getArticleHot: function() {
				let that = this;
				getArticleHotList().then(res => {
					that.$set(that, 'articleList', res.data);
				});
			},
			getCidArticle: function() {
				let that = this;
				if (that.active == 0) return;
				let limit = that.limit;
				let page = that.page;
				let articleList = that.articleList;
				if (that.status) return;
				getArticleList(that.active, {
					page: page,
					limit: limit
				}).then(res => {
					let articleListNew = [];
					let len = res.length;
					articleListNew = articleList.concat(res.data.list);
					that.page++;
					that.$set(that, 'articleList', articleListNew);
					that.status = limit > len;
					that.page = that.page;
				});
			},
			getArticleCate: function() {
				let that = this;
				getArticleCategoryList().then(res => {
					this.active = res.data[0].article_category_id
					that.$set(that, 'navList', res.data);
					this.getCidArticle();
				});
			},
			tabSelect(active) {
				this.active = active;
				if (this.active == 0) this.getArticleHot();
				else {
					this.$set(this, 'articleList', []);
					this.page = 1;
					this.status = false;
					this.getCidArticle();
				}
			}

		}
	}
</script>

<style lang="scss" scoped>
	.bgColor {
		background: #549CE3;
	}

	.header {
		position: relative;
		z-index: 6;
		display: flex;
		align-items: center;
		padding-right: 34rpx;
		height: 43px;
		padding-left: 33rpx;
		background: #549CE3;

		.head-menu {
			display: -webkit-box;
			display: -webkit-flex;
			display: flex;
			-webkit-box-align: center;
			-webkit-align-items: center;
			align-items: center;
			height: 27px;
			width: 70px;
			background: rgba(255, 255, 255, .8);
			border-radius: 13px;

			.icon-ic_leftarrow {
				font-size: 32rpx;
				color: #333333 !important;
			}

			.iconfont {
				-webkit-box-flex: 1;
				-webkit-flex: 1;
				flex: 1;
				text-align: center;
				color: #000000 !important;
				box-sizing: border-box;

				&.icon-ic_leftarrow {
					border-right: 1px solid rgba(000, 000, 000, .2) !important;
				}
			}
		}
		.title{
			max-width: 360rpx;
			text-align: center;
			width: 100%;
			color: #fff;
		}
	}

	.page-body {
		display: flex;
		background: #fff;
		overflow: hidden;

		.nav-left {
			width: 250rpx;
			background: #fafafa;

			.nav-left-item {
				height: 100rpx;
				border-right: solid 1px #f1f1f1;
				border-bottom: solid 1px #f1f1f1;
				font-size: 28rpx;
				display: flex;
				align-items: center;
				justify-content: center;
			}

			.nav-left-item:last-child {
				border-bottom: none;
			}
		}

		.nav-right {
			.box {
				display: block;
				overflow: hidden;
				border-bottom: 18rpx solid #f3f3f3;
				display: flex;
				flex-wrap: wrap;
				justify-content: flex-start;
				align-items: flex-start;
				align-content: flex-start;

				/* min-height: 100vh; */
				/*若您的子分类过少想使得每个子分类占满屏请放开上边注视 */
				&:last-child {
					border: none;
					min-height: calc(100vh - 100px);
				}
			}

			.nav-right-item {
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;
				width: 138rpx;
				height: 180rpx;
				text-align: center;
				padding: 11rpx;
				font-size: 24rpx;
				background: #fff;

				.nav-right-tit {
					margin-top: 4rpx;
				}
			}
		}
	}

	.active {
		color: #549CE3;
		background: #fff;
		border-right: 0;
	}

	::-webkit-scrollbar {
		/*取消小程序的默认导航条样式*/
		width: 0;
		height: 0;
		color: transparent;
	}

	.newsList .nav {
		padding: 0 30rpx;
		width: 100%;
		white-space: nowrap;
		box-sizing: border-box;
		padding-top: 43rpx;
	}

	.newsList .nav .item {
		display: inline-block;
		font-size: 32rpx;
		color: #999;
		min-width: 130rpx;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
		position: relative;
		padding-bottom: 20rpx;
		text-align: center;
	}

	.newsList .nav .item.on {
		color: #282828;
	}

	.newsList .nav .item~.item {
		margin-left: 46rpx;
	}

	.newsList .nav .item .line {
		width: 24rpx;
		height: 4rpx;
		border-radius: 2rpx;
		margin: 10rpx auto 0 auto;
		position: absolute;
		bottom: 5rpx;
		left: 50%;
		margin-left: -12rpx;
	}

	.newsList .list .item {
		border-bottom: 1px solid #f0f0f0;
		padding: 35rpx 30rpx;
	}

	.newsList .list .item .pictrue {
		width: 250rpx;
		height: 156rpx;
		border-radius: 16rpx;
	}

	.newsList .list .item .pictrue image {
		width: 100%;
		height: 100%;
		border-radius: 16rpx;
	}

	.newsList .list .item .text {
		width: 360rpx;
		height: 156rpx;
		font-size: 24rpx;
		color: #999;
	}

	.newsList .list .item .text .name {
		font-size: 30rpx;
		color: #282828;
	}

	.newsList .list .item .picList .pictrue {
		width: 335rpx;
		height: 210rpx;
		border-radius: 16rpx;
	}

	.newsList .list .item .picList.on .pictrue {
		width: 217rpx;
		height: 136rpx;
		border-radius: 16rpx;
	}

	.newsList .list .item .picList .pictrue image {
		width: 100%;
		height: 100%;
		border-radius: 16rpx;
	}

	.empty-box {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		margin-top: 200rpx;

		image {
			width: 414rpx;
			height: 240rpx;
		}

		.txt {
			font-size: 26rpx;
			color: #999;
			text-align: center;
		}
	}
</style>